layui.use(['form', 'jquery', 'layer', 'layarea'], function () {
    var form = layui.form,
        layer = layui.layer,
        layarea = layui.layarea,
        $ = layui.jquery;

    // 加载省市区联动
    layarea.render({
        elem: "#area-picker"
    })

    $('#addSupplier').on('click', function () {
        var province = $('.province-selector').parent().find('.layui-input').val()
        var city = $('.city-selector').parent().find('.layui-input').val();
        var county = $('.county-selector').parent().find('.layui-input').val();
        var address = province + city + county;
        $("#supplierAddress").val(address)
    })

    form.on('submit(addSupplier)', function (data) {
        var index = layer.msg("数据提交中，请稍后", {
            icon: 16,
            time: false,
            shade: 0.8
        })

        var formData = data.field;

        $.ajax({
            type: "post",
            url: ctx + "/supplier/addSupplier",
            data: formData,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 5});
                    layer.closeAll("iframe")
                    parent.location.reload()
                } else {
                    layer.msg(data.msg)
                }
            }, error: function (data) {
                layer.msg(data.msg)
            }
        })
        return false;
    })
})